package com.aaa.cars.controller;

import com.aaa.cars.entity.BaseArea;
import com.aaa.cars.service.BaseAreaService;
import com.aaa.common.constants.ReturnStatus;
import com.aaa.common.util.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 统一地区库(省市县区)(BaseArea)表控制层
 *
 * @author makejava
 * @since 2020-12-04 19:25:48
 */
@RestController
@RequestMapping("baseArea")
public class BaseAreaController {
    /**
     * 服务对象
     */
    @Resource
    private BaseAreaService baseAreaService;

    /**
     * 通过主键查询单条数据
     * @param baseAreaid 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ApiOperation("通过主键查询单条数据")
    public BaseArea selectOne(Long baseAreaid) {
        return this.baseAreaService.queryById(baseAreaid);
    }

    /**
     * 查询所有分页加条件查询
     * @param pageNo   第几页
     * @param pageSize 每页显示数量
     * @param baseArea 实体
     * @return Result
     */
    @PostMapping("queryAll")
    @ApiOperation("查询所有分页加条件查询")
    public Result queryAll(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestBody BaseArea baseArea) {
        return this.baseAreaService.queryAll(pageNo, pageSize, baseArea);
    }

    /**
     * 根据ID删除
     * @param baseAreaid
     * @return Result
     */
    @DeleteMapping("deleteById")
    @ApiOperation("根据ID删除")
    public Result deleteById(Long baseAreaid) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), this.baseAreaService.deleteById(baseAreaid));
    }

    /**
     * 更新
     *
     * @param @param baseArea 实例对象
     * @return Result
     */
    @PostMapping("update")
    @ApiOperation("更新")
    public Result update(@ApiParam("更新json数据") @RequestBody BaseArea baseArea) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), this.baseAreaService.update(baseArea));
    }

    /**
     * 添加
     *
     * @param @param baseArea 实例对象
     * @return Result
     */
    @PostMapping("insert")
    @ApiOperation("添加")
    public Result insert(@ApiParam("添加json数据") @RequestBody BaseArea baseArea) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), this.baseAreaService.insert(baseArea));
    }

    /**
     * 查询所有城市省份
     * @param baseArea
     * @return
     */
    @PostMapping("quallAllBase")
    @ApiOperation("查询所有城市省份")
    public Result quallAllBase(@RequestBody BaseArea baseArea){
        return this.baseAreaService.quallAllBase(baseArea);
    }

    /**
     * 门店添加查询
     * @return
     */
    @PostMapping("queryList")
    @ApiOperation("门店添加查询")
    public Result queryList(){
        return this.baseAreaService.queryList();
    }
}